package com.wyd.tool;

import java.util.HashMap;
import java.util.Map;


/**
 * 常用类型，缺少需要添加
 * @author xuxiaoke
 *
 */
public enum Type {

	CHAR("CHAR","String","char"),
	VARCHAR("VARCHAR","String","varchar"),
	LONGVARCHAR("LONGVARCHAR","String","longvarchar"),
	TEXT("LONGVARCHAR","String","text"),
	LONGTEXT("LONGVARCHAR","String","longtext"),
	MEDIUMTEXT("LONGVARCHAR","String","mediumtext"),
	NUMERIC("NUMERIC","java.math.BigDecimal","numeric"),
	DECIMAL("DECIMAL","java.math.BigDecimal","decimal"),
	BIT("BIT","Integer","bit"),
	TINYINT("TINYINT","Integer","tinyint"),
	SMALLINT("SMALLINT","Integer","smallint"),
	SMALLINTUNSIGNED("SMALLINT","Integer","INT UNSIGNED"),
	INTEGER("INTEGER","Integer","int"),
	BIGINT("BIGINT","String","bigint"),
	REAL ("REAL","Float","real"),
	FLOAT ("FLOAT","Double","float"),
	DOUBLE ("DOUBLE","Double","double"),
	BINARY ("BINARY","byte[]","binary"),
	VARBINARY ("VARBINARY","byte[]","varbinary"),
	LONGVARBINARY ("LONGVARBINARY","byte[]","longvarbinary"),
	DATE ("DATE","java.util.Date","date"),
	DATETIME ("TIMESTAMP","java.util.Date","datetime"),
	TIME ("TIME","java.util.Date","time"),
	TIMESTAMP ("TIMESTAMP","java.util.Date","timestamp"),
	BLOB ("BLOB","com.mysql.jdbc.Blob","blob"),
	;
	public String jdbcType;
	public String javaType;
	public String mysqlType;
	
	public static final Map<String, Type> typeMap = new HashMap<>();

	static {
		
		for (int i = 0; i < Type.values().length; i++) {
			Type type = Type.values()[i];
			typeMap.put(type.mysqlType, type);
		}
	}

	Type(String jdbcType, String javaType, String mysqlType) {
		this.javaType = javaType;
		this.jdbcType = jdbcType;
		this.mysqlType = mysqlType;
	}

	public static Type valuesOf(String text) {
		if("INT UNSIGNED".equals(text)){
			text = "int";
		}
		if("BIGINT UNSIGNED".equals(text)){
			text = "BIGINT";
		}
		if("TINYINT UNSIGNED".equals(text)){
			text = "int";
		}
		if("TINYINT UNSIGNED".equals(text)){
			text = "int";
		}
		if("FLOAT UNSIGNED".equals(text)){
			text = "float";
		}
		if (!typeMap.containsKey(text.toLowerCase())) {
			System.out.println("无相应数据类型"+ text);
		}
		return typeMap.get(text.toLowerCase());
	}
}
